package cn.edu.scau.cmi.zeyang.controller;

import java.util.ArrayList;

import cn.edu.scau.cmi.zeyang.composite.consistent.ConsistentMember;
import cn.edu.scau.cmi.zeyang.composite.consistent.ConsistentOrganization;
import cn.edu.scau.cmi.zeyang.composite.consistent.ConsistentPerson;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;

public class ConsistentCompositeController {

	@FXML
	private Button button1;
	@FXML
	private Button button2;
	@FXML
	private Button button3;
	@FXML
	private Button button4;
	@FXML
	private TextArea textArea;

	private ArrayList<String> persons= new ArrayList<String>() {{
		add("软温一号");
		add("软温二号");
		add("软温三号");
		add("软温四号");
		add("软温五号");
		add("软温六号");
		add("软温七号");
	}};

	private int personIndex=0;
	private ArrayList<String> organizations= new ArrayList<String>() {{
		add("羽毛球协会");
		add("排球协会");
		add("溜溜球协会");
		add("网球协会");
		add("篮球协会");
		add("足球协会");
		add("乒乓球协会");
	}};

	private int organizationIndex=0;

	public void initialize() {
		ConsistentOrganization co=new ConsistentOrganization("初始组织֯",null);
		button1.setOnAction(e->{
			co.addChild(new ConsistentOrganization(organizations.get((organizationIndex)%7),co));
			textArea.setText(organizations.get((organizationIndex++)%7)+"组织添加成功");
		});
		button2.setOnAction(e->{
			co.addChild(new ConsistentPerson(persons.get((personIndex)%7),co));
			textArea.setText(persons.get((personIndex++)%7)+"个人添加成功");
		});
		button3.setOnAction(e->{
			co.deleteAll();
			textArea.setText("删除成功");
		});
		button4.setOnAction(e->{
			textArea.setText("");
			for(ConsistentMember component : co.getChildren()) {
				textArea.appendText(component.name+'\n');
			}
		});
	}

}
